using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace MoonFramework.Scripts.Mono
{
    /// <summary>
    /// Mono启动窗口
    /// </summary>
    public class MonoController : MonoBehaviour
    {
        private void Start()
        {
            DontDestroyOnLoad(gameObject);
        }

        private void Update()
        {
            UpdateEvent?.Invoke();
        }

        private event Action UpdateEvent;

        public void Clear()
        {
            UpdateEvent = null;
        }
        
        public void SendEvent(Action _fun)
        {
            UpdateEvent += _fun;
        }
        
        public void RemoveEvent(Action _fun)
        {
            UpdateEvent -= _fun;
        }
        
        public bool CheckEvent(Action _fun)
        {
            return UpdateEvent != null && UpdateEvent.GetInvocationList().Contains(_fun);
        }
    }
}